<template>
		<view class="sort" :class="[whiteBg ? 'bg-white' : '']">
			<view class="sort-item" data-index="3" @click="sortClick">
				<text>价格</text>
				<view class="icon-item">
					<text class="sort-icon npIcon-shang1" :class="sortType==4 ? 'sort-on' : ''"></text>
					<text class="sort-icon npIcon-xia1" :class="sortType==3 ? 'sort-on' : ''"></text>
				</view>
			</view>
			<view class="sort-item" data-index="1" @click="sortClick">
				<text>销量</text>
				<view class="icon-item">
					<text class="sort-icon npIcon-shang1" :class="sortType==2 ? 'sort-on' : ''"></text>
					<text class="sort-icon npIcon-xia1" :class="sortType==1 ? 'sort-on' : ''"></text>
				</view>
			</view>
			<view class="sort-item" data-index="5" @click="sortClick">
				<text>人气</text>
				<view class="icon-item">
					<text class="sort-icon npIcon-shang1" :class="sortType==6 ? 'sort-on' : ''"></text>
					<text class="sort-icon npIcon-xia1" :class="sortType==5 ? 'sort-on' : ''"></text>
				</view>
			</view>
			<view class="sort-item" data-index="7" @click="sortClick">
				<text>最新</text>
				<view class="icon-item">
					<text class="sort-icon npIcon-shang1" :class="sortType==8 ? 'sort-on' : ''"></text>
					<text class="sort-icon npIcon-xia1" :class="sortType==7 ? 'sort-on' : ''"></text>
				</view>
			</view>
		</view>
</template>

<script>
	export default {
		data(){
			return {
				sortType: 3,
			}
		},
		props: {
			whiteBg:{
				type: Boolean,
				default: false
			},
			value: {
				type: [String, Number],
				default: 0
			},
		},
		watch: {
			value() {
				this.sortType = this.value
			},
		},
		methods: {
			sortClick(e) {
				let index = parseInt(e.currentTarget.dataset.index);
				switch(index) {
					case 1:
						this.sortType = this.sortType == 1 ? 2 : 1;
						break;
					case 3:
						this.sortType = this.sortType == 3 ? 4 : 3;
						break;
					case 5:
						this.sortType = this.sortType == 5 ? 6 : 5;
						break;
					case 7:
						this.sortType = this.sortType == 7 ? 8 : 7;
						break;
				}
				this.$emit('click', this.sortType);
			},
		}
	}
</script>

<style>
	.sort {
		border: none;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 28rpx;
		padding: 20rpx 0;
	}
	
	.text-color {
		color: #333;
	}
	
	.sort-item {
		height: 28rpx;
		line-height: 28rpx;
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.icon-item {
		height: 28rpx;
		line-height: 14rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
	
	.sort-icon {
		font-size: 24rpx;
		font-weight: 500;
	}
	
	.sort-on {
		color: #fb515e;
	}
</style>
